import userInfoConfig from "@/router/userInfo.config";
import { Local } from "@/utils/storage";

const userInfo = Local.get('userInfo')

const NavBarConfig= [
    {
        name: 'msg',
        path: '/msg',
        component: () => import('@/views/msg/index.vue'),
        meta: {
            title: '消息',
            icon: '/src/assets/images/wechat.png',
            requiresAuth: true
        }
    },
    {
        name: 'addressbook',
        path: '/addressbook',
        component: () => import('@/views/addressbook/index.vue'),
        meta: {
            title: '通讯录',
            icon: '/src/assets/images/addressbook.png',
            requiresAuth: true
        }
    },
    {
        name:'add',
        path:'/add',
        component: () => import('@/views/add/index.vue'),
        meta: {
            title: '工作台',
            icon: 'wap-home',
            requiresAuth: false
        }
    },
    {
        name: 'school',
        path: '/school',
        component: () => import('@/views/school/index.vue'),
        meta: {
            title: '校园',
            icon: '/src/assets/images/school.png',
            requiresAuth: true
        }
    },
    {
        name: 'my',
        path: '/my',
        component: () => import('@/views/my/index.vue'),
        meta: {
            title: '我的',
            icon: '/src/assets/images/myself.png',
            requiresAuth: true
        },
        children: userInfoConfig
    },
    // {
    //     name: 'work',
    //     path: '/work',
    //     component: () => import('@/views/work/index.vue'),
    //     meta: {
    //         title: '工作台',
    //         icon: 'phone',
    //
    //     }
    // },
    // {
    //     name: 'permission',
    //     path: '/permission',
    //     component: () => import('@/views/school/index.vue'),
    //     meta: {
    //         title: '校园',
    //         icon: 'apps-o',
    //
    //     }
    // }
]

const updateAddRoute = () => {
    if(userInfo){
        const addRoute = NavBarConfig.find(route => route.name === 'add');
        if (addRoute) {
            // 根据用户角色设置 requiresAuth
            addRoute.meta.requiresAuth = userInfo.role === 1 || userInfo.role === 0;
        } else {
            // 如果路由配置不存在，则添加
            NavBarConfig.push({
                name: 'add',
                path: '/add',
                component: () => import('@/views/add/index.vue'),
                meta: {
                    title: '工作台',
                    icon: 'wap-home',
                    requiresAuth: userInfo.role === 1
                }
            });
        }
    }
};
updateAddRoute();
export default NavBarConfig;
